# coding=utf-8
# -*- coding: UTF-8 -*-
#
# This file is part of the kernelstudio package.
#
# (c) 2014-2023 zlin <admin@kernelstudio.com>
#
# For the full copyright and license information, please view the LICENSE file
# that was distributed with this source code.

from flask_restful import marshal_with, reqparse, request  # type: ignore


def is_post_method() -> bool:
    return request.method == 'POST'


def is_get_method() -> bool:
    return request.method == 'GET'


def is_delete_method() -> bool:
    return request.method == 'DELETE'


def is_put_method() -> bool:
    return request.method == 'PUT'


def is_ajax_request() -> bool:
    return request.headers.get('X-Requested-With') == 'XMLHttpRequest'


def create_basic_query_parser():
    parser = reqparse.RequestParser()
    parser.add_argument("keyword", type=str, required=False, nullable=True, )
    parser.add_argument("page", type=int, default=1, required=False, nullable=True, )
    parser.add_argument("offset", type=int, default=15, required=False, nullable=True, )
    return parser
